package com.khson.knows.portal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.khson.knows.portal.model.Permission;
import com.khson.knows.portal.model.User;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author com.khson
* @since 2021-08-23
*/
@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT p.id,p.name" +
            " FROM user u" +
            " LEFT JOIN user_role ur ON u.id=ur.user_id" +
            " LEFT JOIN role r ON r.id=ur.role_id" +
            " LEFT JOIN role_permission rp ON rp.role_id=r.id" +
            " LEFT JOIN permission p ON p.id=rp.permission_id" +
            " WHERE u.id=#{id}")
    List<Permission> findUserPermissionsById(Integer id);

    @Select("select * from user where username=#{username}")
    User findUserByUsername(String username);
}
